package com.glance.browser.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.glance.browser.domain.Author;
import com.glance.browser.domain.KnowledgeItem;

@Transactional(readOnly = true)
public interface AuthorRepository extends JpaRepository<Author, Long> {

	@Query("from KnowledgeItem k where k.author = :author")
	public List<KnowledgeItem> findKnowledgeItemsById(@Param("author") Long author);

	@Query("from KnowledgeItem k inner join k.author a where a.firstName = :firstName and a.lastName = :lastName")
	public List<KnowledgeItem> findKnowledgeItemsByFirstAndLastName(
			@Param("firstName") String firstName,
			@Param("lastName") String lastName);
	
	@Query("from Author where firstName = :firstName and lastName = :lastName")
	public Author findByName(@Param("firstName") String firstName, @Param("lastName") String lastName);
}
